﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ignitron.EEngine.Maths;
using OpenTK;
using OpenTK.Graphics.OpenGL;

namespace Ignitron.EEngine.Adapters.OpenGL
{
    /// <summary>
    /// OpenTK Helper class
    /// </summary>
    public static class Helper
    {
        public static Vector3 ToOpenTK(this EVector3 vec)
        {
            return new Vector3(vec.X, vec.Y, vec.Z);
        }


        public static Vector4 ToOpenTK(this EVector4 vec)
        {
            return new Vector4(vec.X, vec.Y, vec.Z, vec.W);
        }

        public static Matrix4 ToOpenTK(this EMatrix4 mat)
        {
            return new Matrix4(mat.Row0.ToOpenTK(), mat.Row1.ToOpenTK(), mat.Row2.ToOpenTK(), mat.Row3.ToOpenTK());
        }

        public static LightName ToLightName(this int lightIndex)
        {
            switch (lightIndex)
            {
                case 0:
                    return LightName.Light0;
                case 1:
                    return LightName.Light1;
                case 2:
                    return LightName.Light2;
                case 3:
                    return LightName.Light3;
                case 4:
                    return LightName.Light5;
                case 5:
                    return LightName.Light5;
                case 6:
                    return LightName.Light6;
                case 7:
                    return LightName.Light7;
                default:
                    throw new ArgumentOutOfRangeException("lightIndex");
            }
        }

        public static EnableCap ToLightEnableCap(this int lightIndex)
        {
            switch (lightIndex)
            {
                case 0:
                    return EnableCap.Light0;
                case 1:
                    return EnableCap.Light1;
                case 2:
                    return EnableCap.Light2;
                case 3:
                    return EnableCap.Light3;
                case 4:
                    return EnableCap.Light4;
                case 5:
                    return EnableCap.Light5;
                case 6:
                    return EnableCap.Light6;
                case 7:
                    return EnableCap.Light7;
                default:
                    throw new ArgumentOutOfRangeException("lightIndex");
            }
        }

        public static EVector3 ToEE(this Vector3 vec)
        {
            return new EVector3(vec.X, vec.Y, vec.Z);
        }

        public static EVector4 ToEE(this Vector4 vec)
        {
            return new EVector4(vec.X, vec.Y, vec.Z, vec.W);
        }

        public static EMatrix4 ToEE(this Matrix4 mat)
        {
            return new EMatrix4(mat.Row0.ToEE(), mat.Row1.ToEE(), mat.Row2.ToEE(), mat.Row3.ToEE());
        }
    }
}
